package day09;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

import day09.bean.Request;
import day09.bean.Respons;
import day09.bean.User;


/**
 * 客户端
 * @author root
 *
 */
public class Client {
	public static void main(String[] args) {
		try {
			//封装参数
			User user = new User();
			user.setUserName("钉钉");
			user.setPasswd("1234");
			
			Request req = new Request();
			req.setClassName("cn.edu360.day09.service.impl.UserServiceImpl");
			req.setMethod("login");
			req.setValueType(new Class[]{User.class});
			req.setValue(new Object[]{user});
			
			//建立链接，发送请求数据
			Socket s = new Socket("localhost", 9999);
			ObjectOutputStream output = new ObjectOutputStream(s.getOutputStream());
			output.writeObject(req);
			output.flush();
			
			//获取返回结果
			ObjectInputStream objectInputStream = new ObjectInputStream(s.getInputStream());
			Respons readObject = (Respons)objectInputStream.readObject();
			System.out.println(readObject);
			
			//关流
			s.shutdownInput();
			s.shutdownOutput();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
